package main;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import app.action.AppUtilities;
import app.ui.MainFrame;

public class MainStart {
	private static String className = MainStart.class.getName();
	private static String currentPath = System.getProperty("user.dir") + "/";

	private final static Logger LOG = Logger.getLogger(className);
	private static FileHandler logFile = null;

	public static void main(String[] args) {
		// Configure Log file
		try {
			File logFolder = new File(currentPath + "log");
			if(!logFolder.exists()) {
				logFolder.mkdir();
			}
			logFile = new FileHandler(currentPath + "log/" + className + ".log");
			logFile.setFormatter(new SimpleFormatter());
			Logger.getLogger("").addHandler(logFile);
			logFile.setLevel(Level.ALL);
			LOG.setLevel(Level.ALL);

			LOG.info("HELLO");
		}catch (IOException | SecurityException e) {
			e.printStackTrace();
		}

		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}catch (ClassNotFoundException e) {
			LOG.severe(e.getMessage());
		}catch (InstantiationException e) {
			LOG.severe(e.getMessage());
		}catch (IllegalAccessException e) {
			LOG.severe(e.getMessage());
		}catch (UnsupportedLookAndFeelException e) {
			LOG.severe(e.getMessage());
		}

		MainFrame mainFrame;
		try {
			mainFrame = new MainFrame(getAppUtilities());
			mainFrame.setVisible(true);
		}catch (IOException e) {
			LOG.severe(e.getMessage());
		}
	}

	private static AppUtilities getAppUtilities() throws IOException {
		AppUtilities appUtilities = null;
		File file = new File(currentPath + className + ".ini");
		appUtilities = new AppUtilities(file);

		return appUtilities;
	}
}
